package org.geektimes.web.mvc.controller;

import java.util.Hashtable;
import java.util.Map;

public class ModelAndView {
    private Object view;
    private Map model;

    public ModelAndView() {
    }

    public ModelAndView(String viewName) {
        this.view = viewName;
    }

    public ModelAndView(String viewName, Map<String, ?> model) {
        this.view = viewName;
        if (model != null) {
            this.getModel().putAll(model);
        }
    }

    public Map<String, Object> getModel() {
        if (this.model == null) {
            this.model = new Hashtable<String, Object>();
        }
        return this.model;
    }

    public String getViewName() {
        return this.view instanceof String ? (String) this.view : null;
    }

    public void setViewName(String viewName) {
        this.view = viewName;
    }

    public void setModel(Map<String, ?> model) {
        if (model != null) {
            this.getModel().putAll(model);
        }
    }
}
